#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>        // 包含 struct inode 和 struct file 定义
#include <linux/cdev.h>      // 字符设备相关
#include <linux/uaccess.h>   // 包含 copy_from_user 声明
#include <linux/device.h>   // 包含 class_create 和 device_create 的声明
#include <asm/io.h>
#include <linux/platform_device.h>


#define GPIO0_BASE (0xfdd60000)          //定义GPIO0基地址
#define GPIO0_DR (GPIO0_BASE + 0x0004)   //定义GPIO0_DR_H
#define GPIO0_DDR (GPIO0_BASE + 0x000C)  //定义GPIO0_DDR_H

#define GPIOC_BASE 		(0xC001C000)
#define GPIOC_OUT		(0xC001C000 + 0x00)
#define GPIOC_ENB		(0xC001C000 + 0x04)
#define GPIOC_FN0		(0xC001C000 + 0x20)
#define GPIOC_FN1		(0xC001C000 + 0x24)

static struct resource rled_resource[] = 
{
	[0] = DEFINE_RES_MEM(GPIOC_BASE, 0x1000),
    [1] = DEFINE_RES_MEM(GPIOC_OUT, 4),
    [2] = DEFINE_RES_MEM(GPIOC_ENB, 4),
	[3] = DEFINE_RES_MEM(GPIOC_FN0, 4),
	[4] = DEFINE_RES_MEM(GPIOC_FN1, 4),
};

unsigned int led_hwinfo[1] = { 0xc7 };


static int led_cdev_release(struct inode *inode, struct file *filp)
{
    return 0;
}

/* red led device */
static struct platform_device rled_pdev = {
    .name = "led_pdev",
    .id = 0,
    .num_resources = ARRAY_SIZE(rled_resource),
    .resource = rled_resource,
    .dev = {
        .release = led_cdev_release,
        .platform_data = led_hwinfo,
    },

};


static __init int led_pdev_init(void)
{
    printk("pdev init\n");
    platform_device_register(&rled_pdev);
    return 0;

}
module_init(led_pdev_init);


static __exit void led_pdev_exit(void)
{
    printk("pdev exit\n");
    platform_device_unregister(&rled_pdev);

}
module_exit(led_pdev_exit);


MODULE_AUTHOR("Embedfire");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("the example for platform driver");



